package com.example.adapter;

import java.util.ArrayList;

import com.example.bean.Listitem;
import com.example.newhbsj.R;




import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MainAdapters extends BaseAdapter{
	ArrayList<Listitem> mData =new ArrayList<Listitem>();
	private LayoutInflater mInflater;
	public MainAdapters(Context context,ArrayList<Listitem> al){
		this.mInflater=LayoutInflater.from(context);
		mData=al;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mData.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		viewhold view=null;
		if(convertView==null){
			view=new viewhold();
			convertView=mInflater.inflate(R.layout.activity_homeitem, null);
			view.img=(ImageView) convertView.findViewById(R.id.pic);
			view.name=(TextView)convertView.findViewById(R.id.name);
			view.price=(TextView) convertView.findViewById(R.id.prices);
			view.tags=(TextView) convertView.findViewById(R.id.tags);
			view.Phone=(TextView) convertView.findViewById(R.id.Phone);
			view.distance=(TextView) convertView.findViewById(R.id.distance);
			convertView.setTag(view);
		}
		else{
			 view = (viewhold)convertView.getTag();  
		}
		//view.img.setText(mData.get(position).getPic());
		view.name.setText(mData.get(position).getName());
		view.price.setText(mData.get(position).getPrices());  
		view.tags.setText(mData.get(position).getTags());  
		view.Phone.setText(mData.get(position).getPhone());
		view.distance.setText(mData.get(position).getDistance());
		
        return convertView;  
	}
	
	public final class  viewhold{
		
		public ImageView img;   
        public TextView price;  
        public TextView distance;  
        public TextView name;  
		public TextView tags;
		public TextView Phone;
	}

}
